package com.whg.demo.biz;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

import java.io.File;

/**
 * @Author whg
 * @create 2023/6/16 14:23
 * @description：
 */
public class TestExcel {

    public static void main(String[] args) {
        try {
            //单据模板路径
            String filePath = "D:\\home\\project_two\\excel\\out.xls";
            /*Workbook book = Workbook.getWorkbook(new File(filePath));
            //创建excel文件
            File file = new File("D:\\home\\project_two\\excel/单据模板-copy.xlsm");
            file.createNewFile();
            //创建工作簿
            WritableWorkbook workbook = Workbook.createWorkbook(file,book);*/
            WritableWorkbook workbook = Workbook.createWorkbook(new File(filePath));
            //创建sheet1，明细单
            WritableSheet sheet1 = workbook.createSheet( "ztys1",0);
            handelMxd(sheet1);
            //创建sheet2，商品明细
            WritableSheet sheet2 = workbook.createSheet("ztys2",1);
            //写入数据
            workbook.write();
            //关闭工作簿
            workbook.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    /**
     * 处理明细单sheet页
     * @param sheet
     */
    private static void handelMxd(WritableSheet sheet) throws WriteException {
        Label label = null;
        //“出口货物明细单”【A1】
        sheet.mergeCells(0,0,3,1);
        label = new Label(0,0,"出口货物明细单");
        sheet.addCell(label);
        //“信用证号”【E1】
        label = new Label(4,0,"信用证号");
        sheet.addCell(label);
        //“信用证号”-值【F1】
        label = new Label(5,0,"LC0001");
        sheet.addCell(label);
        //“发票号”【G1】
        label = new Label(6,0,"发票号");
        sheet.addCell(label);
        //“发票号”-值【H1】
        label = new Label(7,0,"INV20200911");
        sheet.addCell(label);
        //“银行编号”【E2】
        label = new Label(4,1,"银行编号");
        sheet.addCell(label);
        //“银行编号”-值【F2】
        label = new Label(5,1,"BK0002");
        sheet.addCell(label);
        //“运输方式”【G2】
        label = new Label(6,1,"运输方式");
        sheet.addCell(label);
        //“运输方式”-值【H2】
        label = new Label(7,1,"BY SAE");
        sheet.addCell(label);
        //“合同号码”【G3】
        label = new Label(4,2,"合同号码");
        sheet.addCell(label);
        //“合同号码”-值【F3】
        sheet.mergeCells(5,2,7,2);
        label = new Label(5,2,"PO2020001");
        sheet.addCell(label);
    }
}
